package day06;

/**
 * @author Xiao
 * @date 2021/7/6
 */
public class getMaxAndMin_Array {
    /*
        获取数组最大值和最小值
            设计一个方法，该方法能够同时获取数组的最大值和最小值
     */
    public static void main(String[] args) {
        int[] arr = {1, 3, 5, 7, 9, 2, 4, 6, 8};
        int[] result = getMaxAndMin(arr);
        System.out.println("max:" + result[0]);
        System.out.println("min:" + result[1]);

    }
    public static int[] getMaxAndMin (int[] arr) {
        int max = arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        int[] arr1 ={max, min};
        return arr1;
    }
}
